
#include <config.h>

#ifdef ORIGIN_BORAD
static char *const seria_port = (char *)UART_BASE_ADDR;


#ifdef PL01X
// typedef unsigned int u32;
/*
 * We can use a combined structure for PL010 and PL011, because they overlap
 * only in common registers.
 */
// struct pl01x_regs {
// 	u32	dr;		/* 0x00 Data register */
// 	u32	ecr;		/* 0x04 Error clear register (Write) */
// 	u32	pl010_lcrh;	/* 0x08 Line control register, high byte */
// 	u32	pl010_lcrm;	/* 0x0C Line control register, middle byte */
// 	u32	pl010_lcrl;	/* 0x10 Line control register, low byte */
// 	u32	pl010_cr;	/* 0x14 Control register */
// 	u32	fr;		/* 0x18 Flag register (Read only) */
// // #ifdef CONFIG_PL011_SERIAL_RLCR
// 	u32	pl011_rlcr;	/* 0x1c Receive line control register */
// // #else
// // 	u32	reserved;
// // #endif
// 	u32	ilpr;		/* 0x20 IrDA low-power counter register */
// 	u32	pl011_ibrd;	/* 0x24 Integer baud rate register */
// 	u32	pl011_fbrd;	/* 0x28 Fractional baud rate register */
// 	u32	pl011_lcrh;	/* 0x2C Line control register */
// 	u32	pl011_cr;	/* 0x30 Control register */
// };
// static struct pl01x_regs *pl01x_port = (struct pl01x_regs *)UART_BASE_ADDR;
// #define UART_PL01x_FR_RXFE              0x10
#define UART_PL01x_FR_TXFF              0x20
static void _pl0x1_putc(const char c)
{
	// *seria_port = c;
	// while (pl01x_port->fr & UART_PL01x_FR_TXFF);
	while ((*(int*)(seria_port + 0x18)) & UART_PL01x_FR_TXFF) ;
	*seria_port = c;
}
#else // end pl01x
///////////////8250/////////////////////////////
#define THR_8250 seria_port
#define LSR_PORT_8250 ((char *)(((int*)seria_port)+5))
#define LSR_THRE 0x20
static void _8250_putc(const char c)
{
	while (((*LSR_PORT_8250) & LSR_THRE) == 0);
	*THR_8250 = c;
}
/////////////8250 end///////////////////////////
#endif 
// end uart 8250


#ifdef PL01X
#define _serial_putc _pl0x1_putc
#else
#define _serial_putc _8250_putc
#endif

#include "bare_uart.h"

void serial_putc(const char c)
{
	// _serial_putc('*');
	if (c == '\n') {
		// _serial_putc('^');
		_serial_putc('\r');
	}
	_serial_putc(c);
}
#endif